#include <iostream>

#include "scheduler.hpp"

void message(const std::string & str)
{
    std::cout << str << std::endl;
}

int main()
{
    // number of tasks that can run simultaneously
    // Note: not the number of tasks that can be added,
    // but number of tasks that can be run in parallel
    unsigned int max_n_threads = 12;
    
    // make a new scheduling object.
    // Note: scheduler cannot be moved or copied
    Bosma::Scheduler scheduler(max_n_threads);

    // every second call messge("every seconds")
    scheduler.every(std::chrono::seconds(1), message, "every second");

    scheduler.in(std::chrono::minutes(1), []() { message("in one minute"); });

    // run lambda, then wait a second, run lambda, and so on
    // different from every in that multiple instances of the function will never be run concurrently
    scheduler.interval(std::chrono::seconds(1), []() {
        std::cout << "right away, then once every 6s" << std::endl;
        std::this_thread::sleep_for(std::chrono::seconds(5));
    });

    // https://en.wikipedia.org/wiki/Cron
    scheduler.cron("* * * * *", []() { std::cout << "cron of every minute" << std::endl; });

      // Time formats supported:
  // %Y/%m/%d %H:%M:%S, %Y-%m-%d %H:%M:%S, %H:%M:%S
  // With only a time given, it will run tomorrow if that time has already passed.
  // But with a date given, it will run immediately if that time has already passed.
  scheduler.at("2023-08-03 22:52:15", []() { std::cout << "at a specific time." << std::endl; });

  scheduler.cron("56 22 * * *", []() {std::cout << "every day at 22:56" << std::endl; });
  // destructor of Bosma::Scheduler will cancel all schedules but finish any tasks currently running
  std::this_thread::sleep_for(std::chrono::minutes(10));
}